<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    <meta name="renderer" content="webkit"/>
    <meta name="force-rendering" content="webkit"/>
    <title>修改密码</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="stylesheet" href="css/shop.css">
    <link rel="stylesheet" href="css/weui.min.css">
    <link rel="stylesheet" href="css/jquery-weui.min.css">
    <script src="js/jquery-2.1.4.js"></script>
    <script src="js/jquery-weui.js"></script>
    <script type="text/javascript" src="js/city-picker.js" charset="utf-8"></script>
    <script src="wxJs/utils/contain.js"></script>
    <script src="wxJs/utils/storage.js"></script>
</head>
<style>
    .header {
        background-color: #6670FF;
    }
</style>
<body>
<div class="header">
    <a class="haader-left" href="javascript:window.history.go(-1)"><i class="iconfont icon-left"></i></a>
    <div class="haader-content">修改密码</div>
    <div class="haader-right">

    </div>
</div>
<div style="background-color: #fff;" class="mt10">
    <div class="weui-cell">
        <div class="weui-cell__hd"><label class="weui-label">旧密码</label></div>
        <div class="weui-cell__bd">
            <input class="weui-input" type="password" placeholder="旧密码" id="oldPassword"  maxlength="6" oninput="setNumType(this)">
        </div>
    </div>
    <div class="weui-cell">
        <div class="weui-cell__hd"><label class="weui-label">新密码</label></div>
        <div class="weui-cell__bd">
            <input class="weui-input" type="password" placeholder="请输入新密码" id="newMM1" maxlength="6" oninput="setNumType(this)">
        </div>
    </div>
    <div class="weui-cell">
        <div class="weui-cell__hd"><label class="weui-label">确认密码</label></div>
        <div class="weui-cell__bd">
            <input class="weui-input" type="password" placeholder="请确认新密码" id="newMM2"  maxlength="6" oninput="setNumType(this)">
        </div>
    </div>
</div>
<div class="btn-contain">
    <a href="javascript:;" class="weui-btn weui-btn_primary mt10 xiugai">修改</a>
    <a href="javascript:;" class="weui-btn weui-btn_warn mt10 forgot">忘记密码</a>
</div>
</body>
<script>
    var userId = GetQueryString("userId");
    if (!userId || userId == 0) {
        window.history.back(-1);
    }else {
        $(".forgot").attr("href","forgot.html?userId="+userId)
    }
    var userInfo = getUserInfo(userId);
    if(!userInfo.payNumber){
        window.location.href = "set_pwd.html?userId="+userId;
    }

    $('.xiugai').on("click", function () {
        var oldPassword=$('#oldPassword').val()

        if (!oldPassword || userInfo.payNumber!=oldPassword){
            $.toast("旧密码错误", "forbidden")
            return false;
        }
        var newMM1 = $("#newMM1").val().trim()
        var newMM2 = $("#newMM2").val().trim()
        if (newMM1 && newMM2 && newMM1 == newMM2) {
            $.post(getWeiContextPath() + "/wx/VipUser/setPayNumber", {
                wxUserId: userId,
                payNumber: newMM1
            }, function (res) {
                $.toast("密码修改成功", function () {
                    window.location.replace("me.html?userId=" + userId)
                })
            })
        } else {
            $.toast("新密码两次输入不一致", "forbidden")
        }
    })

    function setNumType(_this) {
        var num = $(_this).val()
        $(_this).val(num.replace(/[^\d]/g,''))
    }

</script>
</html>